package zyl.spring.boot.branch.test.lamdba;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * LambdaTest3类说明:
 *
 * @author z.y.l
 * @version v1.0
 * @date 2020-09-15
 */
public class LambdaTest3 {
    static class CustomerList<T>{
        List<T> list = new ArrayList<>();
        CustomerList<T> add(T t){
            list.add(t);
            return this;
        }
        void forEach(Executor<? super T> executor){
            Objects.requireNonNull(executor);
            for(T a: list){
                executor.runAction(a);
            }
        }
    }
    interface Executor<T>{
        void runAction(T r);
    }
    @Test
    public void test(){
        CustomerList<String> cs = new CustomerList<>();
        cs.add("my").add(" name").add(" zyl").add(" .");
        cs.forEach(System.out::print);
    }
}
